<template>
  <a-modal
    title="通过"
    :width="640"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <div>
      <p>确认该应用将上线到云商店</p>
      <div>
        <label >短信通知：</label>
        <a-radio-group v-model="radio" buttonStyle="solid">
          <a-radio-button :value="true">是</a-radio-button>
          <a-radio-button :value="false">否</a-radio-button>
        </a-radio-group>
      </div>
    </div>
    <template slot="footer">
      <a-button key="cancel" @click="handleCancel">取消</a-button>
      <a-button key="forward" :loading="confirmLoading" type="primary" @click="handleNext()">确定</a-button>
    </template>
  </a-modal>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  name: 'PassModel',
  components: {
  },
  data () {
    return {
      id: '',
      radio: true,
      visible: false,
      confirmLoading: false
    }
  },
  methods: {
    ...mapActions(['AuditPass']),
    pass (record) {
      this.id = record.id
      this.visible = true
    },
    handleCancel () {
      this.visible = false
    },
    handleNext () { // 通过
      this.confirmLoading = true
      var data = {
        id: this.id,
        status: 1,
        notification: this.radio
      }
      this.AuditPass(data)
        .then((res) => this.passSuccess(res))
        .catch(err => this.requestFailed(err))
    },
    passSuccess (res) {
      if (res.status === 200 || res.status === '200') {
        this.$notification['success']({
          message: '成功',
          description: '审核成功',
          duration: 4
        })
        setTimeout(() => {
          this.visible = false
          this.$emit('ok', res)
        }, 1000)
      } else {
        this.requestFailed(res)
      }
      setTimeout(() => {
        this.confirmLoading = false
      }, 1000)
    },
    requestFailed (err) {
      this.$notification['error']({
        message: '错误',
        description: err.message || '请求出现错误，请稍后再试',
        duration: 4
      })
      setTimeout(() => {
        this.confirmLoading = false
      }, 1000)
    }
  }
}
</script>
<style lang="less" scoped>

</style>
